﻿using Engine.Audio;
using Engine.Media;
using Game;

namespace Mekiasm.Common
{
    public class SoundItem
    {
        public string SoundName;
        public StreamingSource streamingSource;
        public StreamingSound streamingSound;
        public bool IsRemove { get; set; }
        public bool IsPause
        {
            get { return Percent == 1f; }
            set { if (value) streamingSound.Pause(); else streamingSound.Play(); }
        }
        public float Percent { get { return streamingSource.ChannelsCount * streamingSource.Position / (float)streamingSource.BytesCount; } }
        public SoundState State { get { return streamingSound.State; } }
        public float Volume { get { return streamingSound.Volume; } set { streamingSound.Volume = value; } }
        public SoundItem(string name)
        {
            SoundName = name;
            streamingSource = ContentManager.Get<StreamingSource>("Mekiasm/sounds/" + SoundName, ".ogg").Duplicate();
            streamingSource.Position = 0;
            streamingSound = new StreamingSound(streamingSource, 0.7f, 1, 0, false);
        }
        public void PlayOnce()
        {
            streamingSource.Position = 0;
            IsPause = false;
        }
        public void Pause()
        {
            IsPause = true;
        }
        public void Play()
        {
            streamingSound.Play();
        }
    }
}
